﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TimKen.DataEntity
{
    public class ShopCartItem 
    {
       private Project _project;
       private int _count;
       /// <summary>
       /// 产品
       /// </summary>
       public Project Project
       {
           get { return _project; }
           set { _project = value; }
       }
       /// <summary>
       /// 数量
       /// </summary>
       public int Count {
           get { return _count; }
           set { _count = value; }
       }
       public decimal Money {
           get { return this._project.Unitprice * this._count; }
       }
       public decimal ShMoney {
           get { return this._project.Unitprice * this._count*Convert.ToDecimal(this._project.TaxRate); }
       }
       public ShopCartItem(Project pro, int cout, bool _isAutho)
       {
           this._project = pro;
           this._count = cout;
           this.isAuthorizationed = _isAutho;
       }
       private bool _isAuthorizationed;
       public bool isAuthorizationed
       {
           get { return this._isAuthorizationed; }
           set { this._isAuthorizationed = value; }
       }
       public bool IsShow {
           get {
                  bool b = true;
                   string productId = this.Project.ProjectId;
                   double sizeNumber =this.Count;      //购买数量
                   double MinMultiple = this.Project.Min;          //最小倍数
                   double MinNumber = this.Project.MinQuantitative;    //最小数量
                   DateTime datetimeRQ = this.Project.Date;    //货期时间
                   int flag = 0;
                   if (datetimeRQ == Convert.ToDateTime("2099-12-30") || datetimeRQ == Convert.ToDateTime("2099-12-31"))
                   {
                       flag = -3;
                       b = false;

                   }
                   //if (productId.Length != 8)
                   //{
                   //    flag = -4;
                   //    b = false;
                   //}
                   //if (!pm.Exists(Convert.ToInt32(productId)))
                   //{
                   //    flag = -5;
                   //    b = false;
                   //}
                   bool isAuthorizationed = this.isAuthorizationed;
                   if (!isAuthorizationed)
                   {
                       b = false;
                       flag = -2;
                   }
                   //if (MinMultiple * MinNumber == 0 || MinMultiple * MinNumber == 1)
                   //{
                   //    b = false;
                   //    continue;
                   //}         //这里的判断还需要梳理
                   if (sizeNumber < MinNumber || sizeNumber % MinMultiple != 0)
                   {
                       flag = -1;
                       b = false;
                   }
                   if (flag == 0)
                   {
                       b = true;
                       //Response.Redirect("/Order/OrderSend.aspx", true);
                   }
                   else if (flag == -1)
                   {
                       b = false;
                       //gvShopCart.Rows[i].BackColor = System.Drawing.Color.Yellow;
                       //Alert("部分产品不符合购买的最小数量和最小倍数!");
                   }
                   else if (flag == -2)
                   {
                       b = false;
                       //Alert("部分产品未授权购买!");
                       //gvShopCart.Rows[i].BackColor = System.Drawing.Color.Red;
                       //e.Row.Style.Add("Color", "red");
                   }
                   else if (flag == -3)
                   {
                       b = false;
                       //Alert("部分产品货期未确认!");
                       //gvShopCart.Rows[i].BackColor = System.Drawing.Color.Red;
                   }
                   else if (flag == -4)
                   {
                       b = false;
                       //Alert("部分产品编号有问题!");
                       //gvShopCart.Rows[i].BackColor = System.Drawing.Color.Red;
                   }
                   else if (flag == -5)
                   {
                       b = false;
                       //Alert("不存在此类型产品!");
                       //gvShopCart.Rows[i].BackColor = System.Drawing.Color.Red;
                   }
                   return b;
           }
       }
    }
}
